import moment from 'moment';

const FORMAT_STRING = 'YYYY-MM-DD';
const FORMATED_TODAY = moment(Date.now()).format(FORMAT_STRING);
const FORMATED_YESTERDAY = moment(Date.now()).subtract(1,'days').format(FORMAT_STRING);

const dayAlias = {};
dayAlias[FORMATED_TODAY] = "今天";
dayAlias[FORMATED_YESTERDAY] = "昨天";

moment.locale("zh-cn");


function getDateShowText(date){
    var md = moment(date);
    var aliasName = dayAlias[md.format(FORMAT_STRING)];
    return aliasName?aliasName:md.format('LL');
}

function getTimeRangeShowText(range){
    if(range && range.length > 0){
        let begin = range[0];
        if(begin){
            begin = moment(begin).format("HH:mm");
        }
        let end = range[1];
        if(end){
            end = moment(end).format("HH:mm");
        }
        return `(${begin}-${end})`;

    } else {
        return '';
    }
}

function getTimeShowText(time){
    return moment(time).format("YYYY-MM-DD HH:mm");
}

export {
    getDateShowText,
    FORMAT_STRING,
    getTimeRangeShowText,
    getTimeShowText
} 